const path = require('path')

import { defineConfig, loadEnv } from '@rsbuild/core'
import { pluginVue2 } from '@rsbuild/plugin-vue2'
import { pluginSass } from '@rsbuild/plugin-sass'
import { pluginSvgSpriteLoader } from 'rsbuild-svg-sprite-loader'

const ConfigGenerator = require('./plugins/config-generator')

export default defineConfig({
    html: {
        template: './public/index.html'
    },
    output: {
        copy: [{ from: './public/config.js' }]
        // assetPrefix: import.meta.env.PUBLIC_PUBLIC_PATH
    },
    plugins: [
        pluginVue2(),
        pluginSass({
            sassLoaderOptions: {
                additionalData: '@import "@/assets/styles/modules/_variables.scss";'
            }
        }),
        pluginSvgSpriteLoader({
            path: path.join(__dirname, 'src/assets/icons'),
            symbolId: 'icon-[name]'
        })
    ],
    source: {
        // 指定入口文件
        entry: {
            index: './src/main.js'
        }
    },
    tools: {
        rspack: {
            resolve: {
                extensions: ['.vue', '.js', '.json'],
                alias: {
                    '@': path.resolve(__dirname, 'src')
                }
            },
            plugins: [new ConfigGenerator()]
        }
    },
    server: {
        open: true,
        proxy: {
            '/glyh/api/mock': {
                target: 'http://127.0.0.1:4523/m1/1942016-0-default',
                changeOrigin: true,
                logLevel: 'debug',
                pathRewrite: {
                    '/glyh/api/mock': ''
                }
            }
        }
    }
})
